/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: HengCrudProperties
 * Author:   zhouheng
 * Date:     2018/6/19 21:44
 * Description: 全局属性文件类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.hengby.hengcrud.config.properties;

import com.hengby.hengcrud.core.util.ToolUtil;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.io.File;

import static com.hengby.hengcrud.core.util.ToolUtil.getTempPath;
import static com.hengby.hengcrud.core.util.ToolUtil.isEmpty;

/**
 * 〈一句话功能简述〉<br> 
 * 〈全局属性文件类〉
 *
 * @author zhouheng
 * @create 2018/6/19
 * @since 1.0.0
 */
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "heng_crud")
public class HengCrudProperties {
    public static final String PREFIX = "heng_crud";
    private Boolean kaptchaOpen = false;
    private Boolean swaggerOpen = false;
    private String fileUploadPath;
    private boolean haveCreatePath = false;

    private Boolean springSessionOpen = false;

    private Boolean cloudService = false;
    private String servletPath;


    /**
     * session 失效时间（默认为30分钟 单位：秒）
     */
    private Integer sessionInvalidateTime = 30 * 60;

    /**
     * session 验证失效时间（默认为15分钟 单位：秒）
     */
    private Integer sessionValidationInterval = 15 * 60;

    public String getFileUploadPath() {
        //如果没有写文件上传路径,保存到临时目录
        if (ToolUtil.isEmpty(fileUploadPath)) {
            return ToolUtil.getTempPath();
        } else {
            //判断有没有结尾符,没有得加上
            if (!fileUploadPath.endsWith(File.separator)) {
                fileUploadPath = fileUploadPath + File.separator;
            }
            //判断目录存不存在,不存在得加上
            if (!haveCreatePath) {
                File file = new File(fileUploadPath);
                file.mkdirs();
                haveCreatePath = true;
            }
            return fileUploadPath;
        }
    }

}